;;; init-prog.el --- program config
;;; Commentary:
;;; Code:

;; whitespace
(use-package whitespace
  :defer t
  :hook ((prog-mode markdown-mode conf-mode) . whitespace-mode)
  :config
  (setq whitespace-style '(face trailing)))

;; Fast search tool `ripgrep'
(use-package rg
  :defer t
  :after projectile
  :hook (after-init . rg-enable-default-bindings)
  :init (setq rg-group-result t
              rg-show-columns t))

;; hideshow
(use-package hideshow
  :defer t
  :diminish hs-minor-mode
  :hook (prog-mode . hs-minor-mode)
  :custom
  (hs-special-modes-alist
   (mapcar 'purecopy
           '((c-mode "{" "}" "/[*/]" nil nil)
             (c++-mode "{" "}" "/[*/]" nil nil)
	         (go-mode "{" "}" "/[*/]" nil nil)
             (rustic-mode "{" "}" "/[*/]" nil nil)))))

;; newcomment
(use-package newcomment
  :defer t
  :ensure nil
  :bind ([remap comment-dwim] . #'comment-or-uncomment)
  :config
  (defun comment-or-uncomment ()
    (interactive)
    (if (region-active-p)
        (comment-or-uncomment-region (region-beginning) (region-end))
      (if (save-excursion
            (beginning-of-line)
            (looking-at "\\s-*$"))
          (call-interactively 'comment-dwim)
        (comment-or-uncomment-region (line-beginning-position) (line-end-position)))))
  :custom
  (comment-auto-fill-only-comments t))

;; sql-indent sql对齐
(use-package sql-indent
  :defer t
  :after (:any sql sql-interactive-mode)
  :delight sql-mode "Σ ")

;; ini 配置
(use-package ini-mode
  :defer t
  :delight "I "
  :mode ("\\.ini\\'"))

;; json 配置
(use-package json-mode
  :defer t
  :delight "J "
  :mode "\\.json\\'")

;; yaml 配置
(use-package yaml-mode
  :defer t
  :delight "ψ "
  :mode "\\.yml\\'")

;; protobuf
(use-package protobuf-mode
  :defer t
  :delight "P "
  :mode "\\.proto\\'")

;; restclient http客户端
(use-package restclient
  :defer t)

;; rainbow parent 彩虹括号
(use-package rainbow-delimiters
  :defer t
  :hook (prog-mode . rainbow-delimiters-mode))

;; color-indentifier-mode 颜色标识
(use-package color-identifiers-mode
  :defer t
  :hook (after-init . global-color-identifiers-mode))

;; TODO
;; dumb-jump 跳转
(use-package dumb-jump
  :defer t
  :config
  (add-hook 'xref-backend-functions #'dumb-jump-xref-activate))

;; format-all 格式化
(use-package format-all
  :defer t
  :hook (prog-mode . format-all-mode))

;; aggressive-indent 对齐
(use-package aggressive-indent
  :hook (prog-mode . aggressive-indent-mode)
  :config
  (add-to-list
   'aggressive-indent-dont-indent-if
   '(and (derived-mode-p 'c++-mode)
         (null (string-match "\\([;{}]\\|\\b\\(if\\|for\\|while\\)\\b\\)"
							 (thing-at-point 'line))))))

;; quickrun
(use-package quickrun
  :defer t
  :config
  ;; ziglang
  (quickrun-add-command "zig"
    '((:command . "zig")
      (:exec . ("%c run %s")))
    :mode 'zig-mode)
  )

;; editorconfig
(use-package editorconfig
  :defer t
  :config
  (editorconfig-mode 1))

(provide 'init-prog)
;;; init-prog.el ends here
